﻿Public Class HDCurveLimitCfg

#Region " 成员变量 "

    Private _pi As ProjectItem
    Private _rti As RefTypeItem

#End Region

#Region " 属性 "

    Public Property RefTypeItem() As RefTypeItem
        Get
            Return _rti
        End Get
        Set(ByVal value As RefTypeItem)
            _rti = value
        End Set
    End Property

#End Region

#Region " 构造函数 "

    Public Sub New()

        ' 此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。

    End Sub

    Public Sub New(ByVal rti As RefTypeItem)

        ' 此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。
        _rti = rti
    End Sub

#End Region
    
    Private Sub HDCurveLimitCfg_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        _pi = MainForm.pi

        Me.nudTempLower.Value = _rti.HDCurveTempDown
        Me.nudTempUpper.Value = _rti.HDCurveTempUp
        Me.nudHumiLower.Value = _rti.HDCurveHumiDown
        Me.nudHumiUpper.Value = _rti.HDCurveHumiUp

    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If Save() = True Then
            'msg.Show("保存成功。")
            Me.DialogResult = Windows.Forms.DialogResult.OK
        Else
            msg.ShowError("设置失败。")
        End If
    End Sub

    Private Function Save() As Boolean

        Try

            _rti.HDCurveTempDown = Me.nudTempLower.Value
            _rti.HDCurveTempUp = Me.nudTempUpper.Value
            _rti.HDCurveHumiDown = Me.nudHumiLower.Value
            _rti.HDCurveHumiUp = Me.nudHumiUpper.Value

            Save = RefTypeService.Update4HDCurve(_rti) > 0

        Catch ex As Exception
            Debug.Write(ex.Message)
            Save = False
        End Try

    End Function

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub nudTempLower_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudTempLower.ValueChanged

        Me.nudTempUpper.Minimum = Me.nudTempLower.Value + 1

    End Sub

    Private Sub nudTempUpper_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudTempUpper.ValueChanged

        Me.nudTempLower.Maximum = Me.nudTempUpper.Value - 1

    End Sub

    Private Sub nudHumiLower_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudHumiLower.ValueChanged

        Me.nudHumiUpper.Minimum = Me.nudHumiLower.Value + 1

    End Sub

    Private Sub nudHumiUpper_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudHumiUpper.ValueChanged

        Me.nudHumiLower.Maximum = Me.nudHumiUpper.Value - 1

    End Sub

End Class